/*     */ package com.zimbra.cs.filter.jsieve;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.filter.ZimbraMailAdapter;
/*     */ import com.zimbra.cs.filter.ZimbraSieveException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.calendar.Util;
/*     */ import java.text.DateFormat;
/*     */ import java.text.ParseException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.ListIterator;
/*     */ import java.util.TimeZone;
/*     */ import org.apache.jsieve.Argument;
/*     */ import org.apache.jsieve.Arguments;
/*     */ import org.apache.jsieve.SieveContext;
/*     */ import org.apache.jsieve.StringListArgument;
/*     */ import org.apache.jsieve.TagArgument;
/*     */ import org.apache.jsieve.exception.SieveException;
/*     */ import org.apache.jsieve.exception.SyntaxException;
/*     */ import org.apache.jsieve.mail.MailAdapter;
/*     */ import org.apache.jsieve.tests.AbstractTest;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CurrentTimeTest
/*     */   extends AbstractTest
/*     */ {
/*     */   static final String BEFORE = ":before";
/*     */   static final String AFTER = ":after";
/*     */   
/*     */   protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context)
/*     */     throws SieveException
/*     */   {
/*  56 */     if (!(mail instanceof ZimbraMailAdapter)) {
/*  57 */       return false;
/*     */     }
/*  59 */     ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
/*     */     
/*     */ 
/*  62 */     String comparator = null;
/*  63 */     if (argumentsIter.hasNext()) {
/*  64 */       Object argument = argumentsIter.next();
/*  65 */       if ((argument instanceof TagArgument)) {
/*  66 */         String tag = ((TagArgument)argument).getTag();
/*  67 */         if ((tag.equals(":before")) || (tag.equals(":after"))) {
/*  68 */           comparator = tag;
/*     */         } else
/*  70 */           throw new SyntaxException("Found unexpected: \"" + tag + "\"");
/*     */       }
/*     */     }
/*  73 */     if (comparator == null) {
/*  74 */       throw new SyntaxException("Expecting \":before\" or \":after\"");
/*     */     }
/*     */     
/*  77 */     DateFormat timeFormat = new SimpleDateFormat("HHmm");
/*     */     TimeZone accountTimeZone;
/*     */     try {
/*  80 */       accountTimeZone = Util.getAccountTimeZone(((ZimbraMailAdapter)mail).getMailbox().getAccount());
/*     */     } catch (ServiceException e) {
/*  82 */       throw new ZimbraSieveException(e);
/*     */     }
/*  84 */     timeFormat.setTimeZone(accountTimeZone);
/*  85 */     Date timeArg = null;
/*  86 */     if (argumentsIter.hasNext()) {
/*  87 */       Object argument = argumentsIter.next();
/*  88 */       if ((argument instanceof StringListArgument)) {
/*  89 */         List<String> valList = ((StringListArgument)argument).getList();
/*  90 */         if (valList.size() != 1)
/*  91 */           throw new SyntaxException("Expecting exactly one time value");
/*  92 */         String timeStr = (String)valList.get(0);
/*     */         try {
/*  94 */           timeArg = timeFormat.parse(timeStr);
/*     */         } catch (ParseException e) {
/*  96 */           throw new SyntaxException(e);
/*     */         }
/*     */       }
/*     */     }
/* 100 */     if (timeArg == null) {
/* 101 */       throw new SyntaxException("Expecting a time value");
/*     */     }
/*     */     
/* 104 */     if (argumentsIter.hasNext()) {
/* 105 */       throw new SyntaxException("Found unexpected argument(s)");
/*     */     }
/* 107 */     Calendar rightNow = Calendar.getInstance(accountTimeZone);
/*     */     
/* 109 */     Calendar timeToCompareWith = Calendar.getInstance(accountTimeZone);
/*     */     
/* 111 */     timeToCompareWith.setTime(timeArg);
/*     */     
/* 113 */     timeToCompareWith.set(rightNow.get(1), rightNow.get(2), rightNow.get(5));
/*     */     
/*     */ 
/* 116 */     return ":before".equals(comparator) ? rightNow.getTime().before(timeToCompareWith.getTime()) : rightNow.getTime().after(timeToCompareWith.getTime());
/*     */   }
/*     */   
/*     */   protected void validateArguments(Arguments arguments, SieveContext context) {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/filter/jsieve/CurrentTimeTest.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */